﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using AKMII.DMRA.Business.Management;
using AKMII.DMRA.Business.Service;
using AKMII.DMRA.Common;
using AKMII.DMRA.Business.Rule;

namespace AKMII.DMRA.Web
{
    public class NewAdminstrator
    {
        public User Admin { get; set; }

        public OperatorStatus OperatorType { get; set; }

        public bool IsSelected { get; set; }

        public string Password { get; set; }
    }

    public class NewMartketDirector
    {
        public User MD { get; set; }

        public OperatorStatus OperatorType { get; set; }

        public bool IsSelected { get; set; }

        public string Password { get; set; }

        public int IsPurchased { get; set; }
    }

    public class CommonUtility
    {
        public static int GetZipIndex(List<LeadBlock> zips, int id)
        {
            return zips.FindIndex(0, delegate(LeadBlock zip) { return (zip.ZipId == id); });
        }

        public static void SendMail(Mail mail)
        {
            CommonSetting setting = SystemConfiguration.CommonSetting;

            SmtpMailService service = new SmtpMailService(setting.SmtpServer, setting.SystemMailAddress, setting.MailPassword);
            service.Send(mail);
        }

        public static List<LeadBlock> GetZips(List<LeadBlock> zips,
            string zipName, string countyName, string cityName, string stateName)
        {
            if (zips != null)
            {
                List<LeadBlock> filterZips = zips;

                if (!string.IsNullOrEmpty(zipName.Trim()))
                {
                    zips = GetZipsByZipName(zips, zipName);
                }

                if (countyName != "All")
                {
                    zips = GetZipsByCountyName(zips, countyName);
                }

                if (cityName != "All")
                {
                    zips = GetZipsByCityName(zips, cityName);
                }

                //if (terrName != "All")
                //{
                //    zips = GetZipsByTerrName(zips, terrName);
                //}

                if (stateName != "All")
                {
                    zips = GetZipsByStateName(zips, stateName);
                }

                return zips;
            }
            else
            {
                return new List<LeadBlock>();
            }
        }

        private static List<LeadBlock> GetZipsByCountyName(List<LeadBlock> zips, string countyName)
        {
            return zips.FindAll(delegate(LeadBlock zip) { return (zip.County == countyName); });
        }

        private static List<LeadBlock> GetZipsByCityName(List<LeadBlock> zips, string cityName)
        {
            return zips.FindAll(delegate(LeadBlock zip) { return (zip.City == cityName); });
        }

        //private static List<LeadBlock> GetZipsByTerrName(List<LeadBlock> zips, string terrName)
        //{
        //    return zips.FindAll(delegate(LeadBlock zip) { return (zip.Territory == terrName); });
        //}

        private static List<LeadBlock> GetZipsByStateName(List<LeadBlock> zips, string stateName)
        {
            return zips.FindAll(delegate(LeadBlock zip) { return (zip.State == stateName); });
        }

        private static List<LeadBlock> GetZipsByZipName(List<LeadBlock> zips, string zipName)
        {
            return zips.FindAll(delegate(LeadBlock zip) { return zip.ZipName.Contains(zipName); });
        }

        private static List<LeadBlock> GetZipsByLeadType(List<LeadBlock> zips, int leadType)
        {
            if (leadType == 1)
            {
                return zips.FindAll(delegate(LeadBlock zip) { return zip.ActiveLeadCount > 0 || zip.LapsedLeadCount > 0 || zip.NeighborLeadCount > 0; });
            }
            else 
            {
                return zips.FindAll(delegate(LeadBlock zip) { return zip.BusinessLeadCount > 0; });
            }
        }
    }
}
